Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extendable-error

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extendable-error

A simple extendable error class that extends Error.

  • 0.1.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
167K
decreased by-84.4%
Maintainers
1
Weekly downloads
 
Created

What is extendable-error?

The extendable-error npm package provides a simple way to create custom error classes in JavaScript by extending the built-in Error class. This is useful for creating more specific error types in your applications, which can help with error handling and debugging.

What are extendable-error's main functionalities?

Creating a Custom Error Class

This feature allows you to create a custom error class by extending the ExtendableError class. The custom error class can have its own name and additional properties or methods if needed.

class MyCustomError extends ExtendableError {
  constructor(message) {
    super(message);
    this.name = 'MyCustomError';
  }
}

try {
  throw new MyCustomError('Something went wrong!');
} catch (error) {
  console.error(error.name); // MyCustomError
  console.error(error.message); // Something went wrong!
  console.error(error.stack); // Stack trace
}

Handling Custom Errors

This feature demonstrates how to handle custom errors by checking the instance of the error. This allows for more specific error handling logic based on the type of error.

class DatabaseError extends ExtendableError {
  constructor(message) {
    super(message);
    this.name = 'DatabaseError';
  }
}

try {
  throw new DatabaseError('Database connection failed!');
} catch (error) {
  if (error instanceof DatabaseError) {
    console.error('A database error occurred:', error.message);
  } else {
    console.error('An unknown error occurred:', error.message);
  }
}

Other packages similar to extendable-error

FAQs

Package last updated on 15 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc